<template>
  <div id="container">
    <el-header class="header">
      <div class="time">北京时间：{{ currentTime }}</div>
    </el-header>
    <el-main class="main">
      <div class="content">
        <el-form>
          <el-form-item label="车辆ID">
            <el-input v-model="carId" placeholder="请输入ID"></el-input>
          </el-form-item>
        </el-form>
        <el-button type="primary" @click.stop="throttleToEvaluationPage">进入评价页面</el-button>
      </div>
    </el-main>
  </div>
</template>

<script>
import {isExist} from "@/api/client/register";
import {throttle} from '@/utils/index.js'

export default {
  name: 'ClientHome',
  data() {
    return {
      carId: '',
      currentTime: '',
      // 时间定时器
      timer: '',
      //节流
      throttleToEvaluationPage: throttle(this.toEvaluationPage, 1000)
    }
  },
  mounted() {
    this.updateTime()
    setInterval(this.updateTime, 1000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
    this.timer = ''
  },
  methods: {
    updateTime() {
      const date = new Date()
      const hours = date.getHours()
      const minutes = date.getMinutes()
      const seconds = date.getSeconds()
      this.currentTime = `${hours}:${minutes}:${seconds}`
    },
    async toEvaluationPage() {
      if(!this.carId) {
        this.$modal.msgWarning('请输入车辆ID')
        return
      }
      let resp = await isExist(this.carId)
      if(resp.code === 200) {
        this.$router.push({ name: 'ClientReview', query: { carId: this.carId }})
      }
    }
  }
}
</script>

<style scoped>
#container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.header {
  background: linear-gradient(to right, #f9a825, #f06292);
  color: white;
  text-align: center;
  line-height: 60px;
}
.main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}
.content {
  height: 134px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}
</style>
